package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SxAttrValue;
import com.ruoyi.system.service.ISxAttrValueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 属性值Controller
 * 
 * @author cq
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/attrValue")
public class SxAttrValueController extends BaseController
{
    @Autowired
    private ISxAttrValueService sxAttrValueService;

    /**
     * 查询属性值列表
     */
    @PreAuthorize("@ss.hasPermi('system:attrValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(SxAttrValue sxAttrValue)
    {
        startPage();
        List<SxAttrValue> list = sxAttrValueService.selectSxAttrValueList(sxAttrValue);
        return getDataTable(list);
    }

    /**
     * 导出属性值列表
     */
    @PreAuthorize("@ss.hasPermi('system:attrValue:export')")
    @Log(title = "属性值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SxAttrValue sxAttrValue)
    {
        List<SxAttrValue> list = sxAttrValueService.selectSxAttrValueList(sxAttrValue);
        ExcelUtil<SxAttrValue> util = new ExcelUtil<SxAttrValue>(SxAttrValue.class);
        util.exportExcel(response, list, "属性值数据");
    }

    /**
     * 获取属性值详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attrValue:query')")
    @GetMapping(value = "/{attrValueId}")
    public AjaxResult getInfo(@PathVariable("attrValueId") Long attrValueId)
    {
        return success(sxAttrValueService.selectSxAttrValueByAttrValueId(attrValueId));
    }

    /**
     * 新增属性值
     */
    @PreAuthorize("@ss.hasPermi('system:attrValue:add')")
    @Log(title = "属性值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SxAttrValue sxAttrValue)
    {
        return toAjax(sxAttrValueService.insertSxAttrValue(sxAttrValue));
    }

    /**
     * 修改属性值
     */
    @PreAuthorize("@ss.hasPermi('system:attrValue:edit')")
    @Log(title = "属性值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SxAttrValue sxAttrValue)
    {
        return toAjax(sxAttrValueService.updateSxAttrValue(sxAttrValue));
    }

    /**
     * 删除属性值
     */
    @PreAuthorize("@ss.hasPermi('system:attrValue:remove')")
    @Log(title = "属性值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attrValueIds}")
    public AjaxResult remove(@PathVariable Long[] attrValueIds)
    {
        return toAjax(sxAttrValueService.deleteSxAttrValueByAttrValueIds(attrValueIds));
    }
}
